<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="pub/top_list2.jsp"%>   
<%
String sql = "select * from category";
String[] params = null;
List<Map<String, Object>> list = db.queryList(sql, params);
List<Map<String, Object>> list2=null;
if(request.getParameter("categoryID")==null){
	MyDB db4 = My.getDb1();
	String sql4="select * from goodinfo where categoryID=1";
	list2= db4.queryList(sql4, params);
	
}else{
	String cid=(String)request.getParameter("categoryID"); 
	String[] param = new String[1];
	param[0] =cid;
	MyDB db2 = My.getDb1();
	String sql1="select * from goodinfo where categoryID=?";
	list2= db2.queryList(sql1, param);
}
%>
<script>
function fun(id){
	var state=5;
	var categoryID=id;
	 $.ajax({
			type : 'post',
			url : 'test.jsp',
			data : {"categoryID":categoryID,"state":state},
			success : function(data) {	
				
			}
		});
}
function search(){
	var goodname=document.getElementById("goodname").value;
	if(goodname==null||goodname==""){
		return;
	}else{
		window.location.href="goods.jsp?goodname="+goodname;
	}
	/* var state=10;
	 $.ajax({
			type : 'post',
			url : 'test.jsp',
			data : {"goodname":goodname,"state":state},
			success : function(data) {	
				window.location.href="goods.jsp"
			}
		}); */
}
</script>
<body style="background-color: #fff;">
	<header class="page-header fixed-header">
		<input type="search"  placeholder="请输入关键词" value="" id="goodname" /> 
		<span onclick="search()">
			<img src="images/serach.png"/>
		</span>
	</header>
	
	<div class="contaniner fixed-cont">
		
		<aside class="assort">
		<%
			for (Map<String, Object> m : list) {
				String categoryName = m.get("categoryName").toString();
				String categoryID=m.get("categoryID").toString();
		%>
		
			<ul>
				<li>
					<img src="images/classify05.png" >
					<span><a href="assort.jsp?categoryID=<%=categoryID %>" style="color:#666"><%=categoryName %></a></span>
				</li>
			</ul>
			<%} %>
		</aside>

		<section class="assort-cont">
			<figure>
				<a href="#">
					<img src="images/classify-ph01.png"/>
				</a>
			</figure>
			<%
			String sclassify="";
			String gimg="";
			String goodname="";
			String productid="";
			for (int i=0;i<list2.size();i++) {
				Map m = (Map)list2.get(i);
				if(!sclassify.equals(m.get("sclassify").toString())){
					sclassify = m.get("sclassify").toString();
				}else{
					continue;
				}
	     	%>
			<dl>
				<dt><%=sclassify %></dt>
				<%
			for (int l=0;l<list2.size();l++) {
				Map x = (Map)list2.get(l);
				if(sclassify.equals(x.get("sclassify").toString())){
				 gimg=x.get("gimg").toString();
				 goodname=x.get("goodname").toString();
				 productid=x.get("productid").toString();
				}else{x.get("gimg").toString();
					continue;
				}
		    %>
				<dd>
					<a href="detail.jsp?productid=<%=productid %>">
						<img src="<%=gimg %>"/>
						<p><%=goodname %></p>
					</a>
				</dd>
				<%} %>
				
			</dl>
			
			<%} %>
		</section>
	</div>
	<%@ include file="pub/bottom_list21.jsp"%> 